# -*- coding: utf-8 -*-

'''
Created on 29.11.2011

@author: vlasovai

@usage:

<!-- common -->
{% load datepicker_init datepicker %}

{% datepicker_init %}

<!-- individual for calendar -->

<script>
    var dp_init = {
        date: '2011-11-20',
        current: '2011-12-15',
        format: 'Y/m/d',
        view: 'moths',
    };
</script>
{% datepicker <element_id> dp_init %}
'''

from django import template

register = template.Library()

class DatepickerNode(template.Node):
    
    def __init__(self, element, options):
        self.element = element
        self.options = options
        
    def render(self, context):
        t = template.loader.get_template('tags/datepicker.html')
        return t.render(template.Context({'element': self.element, 'options': self.options}, autoescape=False))

def datepicker(parser, token):
    try:
        tag_name, element, options = token.split_contents()
    except ValueError:
        raise template.TemplateSyntaxError("%r tag requires exactly two arguments" % token.contents.split()[0])
    
    return DatepickerNode(element,options)

register.tag(datepicker)